package view;

import domain.Car;
import service.CarService;

import java.util.List;
import java.util.Scanner;

public class Windows {
    CarService carService = new CarService();
    static Scanner scanner = new Scanner(System.in);
    private static boolean flag = false;

    public boolean windowsView_user() {
        System.out.println("登录以使用车辆管理系统");
        System.out.println("用户名：");
        String username = scanner.next();
        System.out.println("密码：");
        String password = scanner.next();
        flag = carService.user_login_service(username, password);
        if (flag) {
            System.out.println("登录成功!");
            return flag;
        } else {
            System.out.println("用户名或密码错误！请重新登录！");
            windowsView_user();

        }

        return flag;
    }

    public int windowsView_car() {
        {
            System.out.println("***********欢迎使用车辆管理系统***********");
            System.out.println("1.查询车辆信息");
            System.out.println("2.新增车辆信息");
            System.out.println("3.修改车辆信息");
            System.out.println("4.删除车辆信息");
            System.out.println("5.退出系统");
            System.out.println("******************************");
            int choice = scanner.nextInt();
            return choice;
        }
    }

    public List<Car> car_list() {
        List<Car> carList = carService.carList();
        return carList;
    }

    public int car_add() {
        System.out.println("请输入你想增加的车辆的CarNumber:");
        String carnumber = scanner.next();
        System.out.println("请输入你想增加的车辆的Type:");
        String type = scanner.next();
        System.out.println("请输入你该车辆的是否为新 --是(1) --否(0)");
        int isnew = scanner.nextInt();


        int result = carService.insert_car_service(new Car(0, carnumber, type, isnew, 0));
        return result;
    }

    public int car_update() {
        System.out.println("请输入你想更改的车辆的CarNumber:");
        String carnumber = scanner.next();

        System.out.println("更改你该车辆的是否为维修 --是(1) --否(0)");
        int isrepair = scanner.nextInt();
        int result = carService.update_car_service(new Car(0, carnumber, "ws", 0, isrepair));
        return result;

    }

    public int car_delete() {
        System.out.println("请输入你想更改的车辆的carnumber值:");
        String carnamber = scanner.next();
        Car car = new Car();
        car.setCarnumber(carnamber);
        int result = carService.delete_car_service(car);
        return result;
    }


}
